home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 3 PutContentsIn Igor Pro Folder / Technical Notes / Igor Tech Notes / TN006 DSP support / DFT TEXT < prev    next >
Text File  |  1994-06-03  |  3KB  |  103 lines

  1. | Given a complex input wave and a same size output wave, calculate the
  2. | Discrete Fourier Transform using the direct (slow) method.
  3. | parameter dir should be +1 for forward transform or -1 for reverse.
  4. | input wave is not changed
  5. |
  6. | The x scaling of the output wave should be changed by the caller
  7. | with a statement such as
  8. | Setscale/p x,0,1/numpnts(inw)/(pnt2x(inw,1)-pnt2x(inw,0)), outw  
  9. |
  10. | Requires: DFT1()
  11. |
  12. Function DFT(inw,outw,dir)
  13.     wave/c inw,outw
  14.     variable dir
  15.     
  16.     variable n=numpnts(inw)
  17.     variable nn
  18.     variable dx= pnt2x(inw,1)-pnt2x(inw,0)
  19.     
  20.     nn=0
  21.     do
  22.         outw[nn]= DFT1(inw,dir,nn/(n*dx))
  23.         nn+=1
  24.     while(nn<n)
  25.     
  26.     return 0
  27. end
  28.  
  29.  
  30. | Given a complex input wave and a complex output wave (probably of different size),
  31. | calculate the Discrete Fourier Transform using the direct (slow) method for the frequencies
  32. | in the range of fMin to fMax, inclusive.  outw[0] will contain the value for fMin, and outw[n-1]
  33. | will contain the value for fMax.
  34. | parameter dir should be +1 for forward transform or -1 for reverse.
  35. | input wave is not changed.
  36. |
  37. | The x scaling of the output wave should be changed by the caller
  38. | with a statement such as
  39. | Setscale/I x, fMin,fMax, outw
  40. | The values of the output wave have the normal multiplication factor of inPts=numpnts(inw);
  41. |    if the input wave is a record of repetitive data, divide outwave by inPts.  
  42. |
  43. | Requires: DFT1()
  44. |
  45. Function DFTVarRes(inw,outw,fMin,fMax,dir)        | Do transform between fMin and fMax
  46.     wave/c inw,outw
  47.     variable fMin,fMax,dir
  48.     
  49.     variable n=numpnts(outw)
  50.     variable freq
  51.     variable nn
  52.     
  53.     nn=0
  54.     do
  55.         freq= fMin+nn/(n-1)*(fMax-fMin)
  56.         outw[nn]= DFT1(inw,dir,freq)
  57.         nn+=1
  58.     while(nn<n)
  59.         
  60.     return 0
  61. end
  62.  
  63.  
  64. | Given a complex input wave and a same size output wave, calculate the
  65. | Discrete Fourier Transform using the direct (slow) method.
  66. | parameter dir should be +1 for forward transform or -1 for reverse.
  67. | input wave is not changed  
  68. | parameter freq is the frequency at which  the forward DFT will be computed,
  69. | it is the time at which the inverse DFT is computed.
  70. | Returns complex value of Discrete Fourier Transform at given frequency (forward)
  71. | or time (backward)
  72. |
  73. Function/C DFT1(inw,dir,freq)
  74.     wave/c inw
  75.     variable dir,freq
  76.     
  77.     variable n=numpnts(inw)
  78.     variable/c w,wrot
  79.     variable kk
  80.     variable dx=  pnt2x(inw,1)-pnt2x(inw,0)
  81.     variable pointFreq= freq*dx     |pointFreq varies from 0 to 1.  0 for Constant Term, 1 for max frequency term (it plays role of nn/n in DFT Function)
  82.     
  83.     Variable/C out=0
  84.     
  85.     kk=0
  86.     w= cmplx(1,0)
  87.     wrot= cmplx(cos(2*pi*pointFreq),sin(2*pi*pointFreq))    | was     wrot= cmplx(cos(2*pi*nn/n),sin(2*pi*nn/n)) in DFT()
  88.     if(dir== -1)
  89.         wrot= conj(wrot)
  90.     endif
  91.     do
  92.         out += inw[kk]*w
  93.         w *= wrot
  94.         kk+=1
  95.     while(kk<n)
  96.     
  97.     if(dir== -1)
  98.         out /= n
  99.     endif
  100.     
  101.     return out
  102. end
  103.